home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.basic;
-
- import com.sun.java.swing.AbstractButton;
- import com.sun.java.swing.ButtonModel;
- import com.sun.java.swing.Icon;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.LookAndFeel;
- import com.sun.java.swing.SwingUtilities;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.plaf.ComponentUI;
- import com.sun.java.swing.plaf.ToggleButtonUI;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.Rectangle;
- import java.io.Serializable;
-
- public class BasicRadioButtonUI extends BasicToggleButtonUI implements Serializable {
- protected static final Insets defaultMargin = new Insets(2, 2, 2, 2);
- protected Icon icon = null;
- protected static ToggleButtonUI radioButtonUI;
- ButtonModel model;
-
- public Icon createIcon() {
- return UIManager.getIcon("RadioButton.icon");
- }
-
- public static ComponentUI createUI(JComponent b) {
- if (radioButtonUI == null) {
- radioButtonUI = new BasicRadioButtonUI();
- }
-
- return radioButtonUI;
- }
-
- public Insets getDefaultMargin(AbstractButton b) {
- return defaultMargin;
- }
-
- public Dimension getPreferredSize(JComponent c) {
- if (((Container)c).getComponentCount() > 0) {
- return null;
- } else {
- AbstractButton b = (AbstractButton)c;
- String text = b.getText();
- Icon radioIcon = b.getIcon();
- if (radioIcon == null) {
- radioIcon = this.icon;
- }
-
- Font font = ((Component)b).getFont();
- FontMetrics fm = ((Component)b).getToolkit().getFontMetrics(font);
- Rectangle iconR = new Rectangle();
- Rectangle textR = new Rectangle();
- Rectangle viewR = new Rectangle(32767, 32767);
- SwingUtilities.layoutCompoundLabel(fm, text, radioIcon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewR, iconR, textR, text == null ? 0 : ((BasicToggleButtonUI)this).getDefaultTextIconGap(b));
- Rectangle r = iconR.union(textR);
- Insets insets = ((JComponent)b).getInsets();
- r.width += insets.left + insets.right;
- r.height += insets.top + insets.bottom;
- return r.getSize();
- }
- }
-
- protected void installDefaults(JComponent c) {
- super.installDefaults(c);
- this.icon = this.createIcon();
- LookAndFeel.installColorsAndFont(c, "RadioButton.background", "RadioButton.foreground", "RadioButton.font");
- }
-
- public synchronized void paint(Graphics g, JComponent c) {
- AbstractButton b = (AbstractButton)c;
- this.model = b.getModel();
- Dimension size = ((Component)c).getSize();
- int var10000 = size.width;
- var10000 = size.height;
- Font f = ((Component)c).getFont();
- g.setFont(f);
- FontMetrics fm = g.getFontMetrics();
- Rectangle viewRect = new Rectangle(size);
- Rectangle iconRect = new Rectangle();
- Rectangle textRect = new Rectangle();
- Icon altIcon = b.getIcon();
- String text = SwingUtilities.layoutCompoundLabel(fm, b.getText(), altIcon != null ? altIcon : this.icon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, ((BasicToggleButtonUI)this).getDefaultTextIconGap(b));
- if (c.isOpaque()) {
- g.setColor(((Component)b).getBackground());
- g.fillRect(0, 0, size.width, size.height);
- }
-
- if (altIcon != null) {
- if (!this.model.isEnabled()) {
- altIcon = b.getDisabledIcon();
- } else if (this.model.isPressed() && this.model.isArmed()) {
- altIcon = b.getPressedIcon();
- if (altIcon == null) {
- altIcon = b.getSelectedIcon();
- }
- } else if (this.model.isSelected()) {
- altIcon = b.getSelectedIcon();
- } else if (b.isRolloverEnabled() && this.model.isRollover()) {
- altIcon = b.getRolloverIcon();
- }
-
- if (altIcon == null) {
- altIcon = b.getIcon();
- }
-
- altIcon.paintIcon(c, g, iconRect.x, iconRect.y);
- } else {
- this.icon.paintIcon(c, g, iconRect.x, iconRect.y);
- }
-
- if (text != null) {
- if (this.model.isEnabled()) {
- g.setColor(((Component)b).getForeground());
- BasicGraphicsUtils.drawString(g, text, this.model.getMnemonic(), textRect.x, textRect.y + fm.getAscent());
- } else {
- g.setColor(((Component)b).getBackground().brighter());
- BasicGraphicsUtils.drawString(g, text, this.model.getMnemonic(), textRect.x + 1, textRect.y + fm.getAscent() + 1);
- g.setColor(((Component)b).getBackground().darker());
- BasicGraphicsUtils.drawString(g, text, this.model.getMnemonic(), textRect.x, textRect.y + fm.getAscent());
- }
-
- if (((JComponent)b).hasFocus() && b.isFocusPainted() && textRect.width > 0 && textRect.height > 0) {
- this.paintFocus(g, textRect, size);
- }
- }
-
- }
-
- protected void paintFocus(Graphics g, Rectangle textRect, Dimension size) {
- }
- }
-